// State 接口
interface State {
    void handle(Context context);
}

// Context 类
class Context {
    private State state;

    public void setState(State state) {
        this.state = state;
    }

    public void request() {
        state.handle(this);
    }
}

// ConcreteStateA 类
class ConcreteStateA implements State {
    @Override
    public void handle(Context context) {
        System.out.println("ConcreteStateA handle");
        context.setState(new ConcreteStateB());
    }
}

// ConcreteStateB 类
class ConcreteStateB implements State {
    @Override
    public void handle(Context context) {
        System.out.println("ConcreteStateB handle");
        context.setState(new ConcreteStateA());
    }
}

// 测试类
public class StateTest {
    public static void main(String[] args) {
        Context context = new Context();
        context.setState(new ConcreteStateA());
        context.request(); // 输出：ConcreteStateA handle
        context.request(); // 输出：ConcreteStateB handle
    }
}